home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Frameworks / TransSkel 3.24 / Demos / Pascal Demos / MultiSkel / MSkelEdit.p next >
Text File  |  1996-01-25  |  3KB  |  151 lines

  1. unit MultiSkelEdit;
  2.  
  3. interface
  4.  
  5.     uses
  6.         Types, Events, QuickDrawText, QuickDraw, Windows, Menus, TextEdit,
  7.         Scrap, ToolUtils, TransSkel, MSkelGlobals;
  8.  
  9.     procedure EditWindInit;
  10.     procedure EditWindEditMenu (item: Integer);
  11.  
  12. implementation
  13.  
  14.     const
  15.         undo = 1;
  16.         cut = 3;
  17.         copy = 4;
  18.         paste = 5;
  19.         clear = 6;
  20.  
  21.     var
  22.  
  23.         teEdit: TEHandle;
  24.  
  25.  
  26.     procedure Mouse (pt: Point;
  27.                                     t: LongInt;
  28.                                     mods: Integer);
  29.     begin
  30.         TEClick(pt, Boolean(BitAnd(mods, shiftKey) <> 0), teEdit);
  31.     end;
  32.  
  33.  
  34.     procedure Key (c: char;
  35.                                     code: Integer;
  36.                                     mods: Integer);
  37.     begin
  38.         TEKey(c, teEdit);
  39.     end;
  40.  
  41.  
  42.     procedure Update (resized: Boolean);
  43.         var
  44.             r: Rect;
  45.     begin
  46.         r := editWind^.portRect;
  47.         EraseRect(r);
  48.         r.left := r.left + 4;
  49.         r.bottom := r.bottom - 2;
  50.         r.top := r.top + 2;
  51.         r.right := r.right - 19;
  52.         if (resized) then
  53.             begin
  54.                 teEdit^^.destRect.right := r.right;
  55.                 teEdit^^.viewRect := r;
  56.                 TECalText(teEdit);
  57.             end;
  58.         DrawGrowBox(editWind);
  59.         TEUpdate(r, teEdit);
  60.     end;
  61.  
  62.  
  63.     procedure Activate (active: Boolean);
  64.     begin
  65.         DrawGrowBox(editWind);
  66.         if (active) then
  67.             begin
  68.                 TEActivate(teEdit);
  69.                 DisableItem(editMenu, undo);
  70.             end
  71.         else
  72.             begin
  73.                 TEDeactivate(teEdit);
  74.                 EnableItem(editMenu, undo);
  75.             end;
  76.     end;
  77.  
  78.  
  79.     procedure Clobber;
  80.     begin
  81.         TEDispose(teEdit);
  82.         DisposeWindow(editWind);
  83.     end;
  84.  
  85.  
  86.     procedure Idle;
  87.     begin
  88.         TEIdle(teEdit);
  89.     end;
  90.  
  91.  
  92.     procedure EditWindInit;
  93.         var
  94.             r: Rect;
  95.             str: Str255;
  96.             ignore: Boolean;
  97.     begin
  98.         if (SkelQuery(skelQHasColorQD) <> 0) then
  99.             editWind := GetNewCWindow(editWindRes, nil, WindowPtr(-1))
  100.         else
  101.             editWind := GetNewWindow(editWindRes, nil, WindowPtr(-1));
  102.         if (editWind = nil) then
  103.             exit(EditWindInit);
  104.         ignore := SkelWindow(editWind, @Mouse, @Key, @Update, @Activate, nil, @Clobber, @Idle, true);
  105.  
  106.         TextFont(0);
  107.         TextSize(0);
  108.  
  109.         r := editWind^.portRect;
  110.         r.left := r.left + 4;
  111.         r.bottom := r.bottom - 2;
  112.         r.top := r.top + 2;
  113.         r.right := r.right - 19;
  114.         teEdit := TENew(r, r);
  115.         str := 'This is the text editing window.X';
  116.         str[length(str)] := chr(13);    { make last char (X) a carriage return }
  117.         TEInsert(Ptr(LongInt(@str) + 1), LongInt(length(str)), teEdit);
  118.     end;
  119.  
  120.  
  121.     procedure EditWindEditMenu (item: Integer);
  122.         var
  123.             ignore: OSErr;
  124.     begin
  125.         case item of
  126.             cut: 
  127.                 begin
  128.                     TECut(teEdit);
  129.                     ignore := ZeroScrap;
  130.                     ignore := TEToScrap;
  131.                 end;
  132.             copy: 
  133.                 begin
  134.                     TECopy(teEdit);
  135.                     ignore := ZeroScrap;
  136.                     ignore := TEToScrap;
  137.                 end;
  138.             paste: 
  139.                 begin
  140.                     ignore := TEFromScrap;
  141.                     TEPaste(teEdit);
  142.                 end;
  143.             clear: 
  144.                 begin
  145.                     TEDelete(teEdit);
  146.                 end;
  147.         end;
  148.     end;
  149.  
  150.  
  151. end.